package com.example.beikeyigou.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.example.beikeyigou.R;

public class PromptDialog extends Dialog implements View.OnClickListener {
    private TextView titleTv, promptTv, negtiveTv ,positiveTv;

    public PromptDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_prompt);

        findView();

        negtiveTv.setOnClickListener(this);
        positiveTv.setOnClickListener(this);
    }

    private void findView() {
        titleTv = findViewById(R.id.dialog_prompt_title);
        negtiveTv = findViewById(R.id.dialog_prompt_confirm);
        positiveTv = findViewById(R.id.dialog_prompt_cancel);
        promptTv = findViewById(R.id.dialog_prompt_information);
    }

    /**
     * 设置确定取消按钮的回调
     */
    public PromptDialog.OnClickBottomListener onClickBottomListener;
    public PromptDialog setOnClickBottomListener(PromptDialog.OnClickBottomListener onClickBottomListener) {
        this.onClickBottomListener = onClickBottomListener;
        return this;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.dialog_prompt_cancel:
                if (onClickBottomListener!= null) {
                    onClickBottomListener.onNegtiveClick();
                }
                break;
            case R.id.dialog_prompt_confirm:
                if (onClickBottomListener!= null) {
                    onClickBottomListener.onPositiveClick();
                }
                break;
        }
    }

    public interface OnClickBottomListener{
        //点击确定按钮事件
        public void onPositiveClick();
        //点击取消按钮事件
        public void onNegtiveClick();
    }

    public PromptDialog setTitleTv(String title) {
        this.titleTv.setText(title);
        return this;
    }

    public PromptDialog setPromptTv(String prompt) {
        this.promptTv.setText(prompt);
        return this;
    }
}
